#ifndef GAME_H
#define GAME_H

#include <QGraphicsView>
#include <QList>
#include "player.h"
#include "obstacle.h"
#include"jellyfish.h"
#include "background.h"
#include "menu.h"
#include<QMessageBox>

class QLabel;
class QTimer;
class Coin;
class Menu;

class Game : public QGraphicsView {
    Q_OBJECT
public:
    explicit Game(QWidget* parent = nullptr);
    void keyPressEvent(QKeyEvent* event) override;
    void showMenu();
    void startGame();
private slots:
    void updateGame();      // 主游戏循环
    void spawnObstacle();
    void spawnJellyfish();
    void cleanJellyfish();
    void showGameOverDialog();

private:
    void resetGame();       // 重置游戏
    void checkCollisions(); // 障碍物碰撞检测
   void cleanObstacles();  // 清理障碍物
   void updateScoreDisplay();


    // 游戏元素
    QGraphicsScene* scene;
    Player* player;
    Background* bg1;
    Background* bg2;
    Menu* gameMenu;
    QGraphicsScene* currentScene;
    bool isGameStarted;
    // 对象容器
    QList<Obstacle*> obstacles;
    QList<Jellyfish*>jellyfishList;
    QList<Background*> backgrounds;//背景层容器
    // 定时器
    QTimer* timer;
    QTimer physicsTimer;
        // 主循环定时器
    QTimer* spawnTimer;     // 障碍物生成定时器
    QTimer*jellyfishTimer;

    // 界面元素
    QLabel* scoreLabel;

    // 游戏状态
    int score=0;
    int jellyfishCollected = 0;
    bool gameOver;
    const QRect JELLYFISH_AREA = QRect(0, 0, 800, 600); // 根据实际窗口大小调整
};

#endif // GAME_H
